package com.cfl.ticketmodule.service.impl;

import java.util.ArrayList;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cfl.model.TicketNumber;
import com.cfl.ticketmodule.dao.TicketNumberMapper;
import com.cfl.ticketmodule.service.TicketNumberService;

@Service("ticketNumberService")
public class TicketNumberServiceImpl implements TicketNumberService{

	@Autowired
	private TicketNumberMapper ticketNumberMapper;
	
	public void addTicketNumber(String number) throws Exception{
		// TODO Auto-generated method stub
		try {
			TicketNumber ticketNumber = new TicketNumber();
			ticketNumber.setTid(UUID.randomUUID().toString());
			ticketNumber.setNumber(number);
			ticketNumberMapper.insert(ticketNumber);
		} catch (Exception e) {
			// TODO: handle exception
			throw e;
		}
	}
	
	public ArrayList<TicketNumber> getAll() throws Exception {
		try {
			return ticketNumberMapper.selectAll();
		} catch (Exception e) {
			throw e;
		}
	}
	
	public TicketNumber findByNumber(String number) throws Exception {
		try {
			return ticketNumberMapper.selectByNumber(number);
		} catch (Exception e) {
			throw e;
		}
	}
	
	public TicketNumber findByTid(String tid) throws Exception {
		try {
			return ticketNumberMapper.selectByTid(tid);
		} catch (Exception e) {
			throw e;
		}
	}
}
